<?php
/**
 * Created by PhpStorm.
 * Author: sitenv@aliyun.com
 * CreateTime: 2021/07/09 14:47
 * Blog：www.myblogs.xyz
 */

namespace app\common\model;


class Verify extends Common
{
    protected $name = 'verify';
    protected $pk = 'verify_id';

    public function VerifyCode($param, $type)
    {
        if (empty($param['account'])){
            $this->error = '请输入手机号';
            return false;
        }
        if (empty($param['verify_code'])){
            $this->error = '请输入短信验证码';
            return false;
        }
        if (!is_mobile($param['account'])){
            $this->error = '请输入正确的手机号';
            return false;
        }
        $this->orders = 'day desc,time desc';
        $verify_data = $this->getFind(['account'=>$param['account'],'type'=>$type]);
        if (empty($verify_data)){
            $this->error = '验证码有误';
            return false;
        }
        if ($verify_data['code'] != $param['verify_code']){
            $this->error = '验证码有误';
            return false;
        }
        if ($verify_data['time'] < NEW_TIME){
            $this->error = '验证码已失效';
            return false;
        }
        return true;
    }

}